package cn.basic.social.demo.vo;

import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

@Data
@NoArgsConstructor
public class JsonResult<T> implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * 返回代号
     */
    private Integer code;
    /**
     * 返回信息
     */
    private String msg;
    /**
     * 返回数据
     */
    private T data;


    public static <T> JsonResult<T> getInstant(Integer code, String msg, T data) {
        return new JsonResult<>(code, msg, data);
    }

    public static <T> JsonResult<T> getInstant(Integer code, String msg) {
        return new JsonResult<>(code, msg);
    }

    private JsonResult(Integer code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    private JsonResult(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public static <T> JsonResult<T> getInstant(Integer code, T data) {
        return new JsonResult<>(code, "", data);
    }

    public static <T> JsonResult<T> success(T data) {
        return JsonResult.getInstant(0, data);
    }


    /**
     * 是否成功
     *
     * @param
     * @return
     * @author bfd.zlf
     * @date 11:24 2023/9/14
     */
    public boolean isSuccess() {
        if (this.code != null && this.code == 200) {
            return true;
        }
        return false;
    }
}
